const http = require('http')
const Router = require('./router')

function Application(){
    this.router = new Router
}

Application.prototype.get = function(path,handler){
    this.router.get(path,handler)
}

Application.prototype.post = function(path,handler){
    this.router.post(path,handler)
}

Application.prototype.listen = function(){
    let server = http.createServer((req,res)=>{
        function done(){
            res.end(`Cannot ${req.url} ${req.method}`)
        }
        this.router.handle(req,res,done)
    })
    server.listen(...arguments)
}

module.exports = Application
